package com.atguigu.iterator;

import java.util.Iterator;

/**
 * @program: design-patterns
 * @author: yangshen
 * @description: 计算机学院迭代器
 * @create: 2022-03-06 20:37
 **/
public class ComputerCollegeIterator implements Iterator {

    //这里我们需要Department 是以怎样的方式存放
    Department[] departments;
    //遍历的位置
    int position = 0;

    /**
     * 把具体要遍历的内存传进来
     * @param departments 院系的集合
     */
    public ComputerCollegeIterator(Department[] departments) {
        this.departments = departments;
    }

    /**
     * 判断是否还有下一个元素
     * @return 是有还有元素
     */
    @Override
    public boolean hasNext() {
        if (position >= departments.length || null == departments[position]){
            return false;
        }else {
            return true;
        }
    }

    @Override
    public Object next() {
        Department department = departments[position];
        position += 1;
        return department;
    }

    /**
     * 空实现
     */
    @Override
    public void remove() {

    }
}
